from typing import List
class Solution:
    def minCost(self, colors: str, neededTime: List[int]) -> int:
        n = len(colors)
        res = 0
        i = 0
        while i<n: 
            j = i
            while j<n and colors[j]==colors[i]:
                j+=1
            cost = sum(neededTime[i:j])-max(neededTime[i:j])
            res+=cost
            i = j
        return res